package com.zsl.provider.ctrl;

import com.zsl.api.OperationApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * openfeign 测试服务
 * 模式生产者，提供sdk
 * 根据euraka对外提供服务
 * application.name=provider
 */
@RestController
public class OperationProviderCtrl implements OperationApi {

	@Value("${server.port}")
	String port;

	@Override
	public String getOK(@RequestParam String word) {
		return "I'm OK:" + word + "----" + port;
	}

	@Override
	public String setUser(Map user) {
		return user.get("name").toString();
	}


	private AtomicInteger count = new AtomicInteger();

	@Override
	public String trytime(){
		try {
			System.out.println("准备睡");
			if(port.equals("7010")) {
				Thread.sleep(6000);
			}



		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		int i = count.getAndIncrement();
		System.out.println(port + " 好的 ====第：" + i + "次调用");
		return "OK-" + port;
	}
}
